<template>
  <div @mouseenter="isxz = true" @mouseleave="isxz = false">
    <!-- 选择城市类型 -->
    <!-- 鼠标进入，离开 用 mouseenter  mouseleave 不支持冒泡-->
    <div class="textbox">
      <!-- 城市 -->
      <div
        class="lm"
        :class="{gaibian:masoshuoqu==index&&isxz}"
        v-for="(item,index) in psCtdata"
        :key="index"
        @mouseenter="masoshuoqu = index"
      >
        {{item.type}}
        <span>></span>
      </div>
    </div>
    <!-- 选择栏 -->
    <div class="xz" v-if="isxz&&psCtdata.length">
      <ul>
        <li
          v-for="(item,index) in psCtdata[masoshuoqu].children"
          :key="index"
          @click="chenshi(item.city)"
        >
          <i class="numb">{{index+1}}</i>
          <span class="ct">{{item.city}}</span>
          {{item.desc}}
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
export default {
  props: ["psCtdata"],
  data() {
    return {
      // 鼠标经过触发的栏目的索引
      masoshuoqu: 0,
      // 城市列表的显示隐藏
      isxz: false,
    };
  },
  methods: {
    chenshi(val) {
      this.isxz = false;
      this.$emit("chenshi", val);
    },
  },
};
</script>

<style lang="less" scoped>
.textbox {
  .lm {
    position: relative;
    z-index: 3;
    cursor: pointer;
    background-color: #fff;
    padding: 0 20px;
    font-size: 14px;
    color: #000;
    line-height: 40px;
    border-top: 1px solid #e4e4e4;
    border-right: 1px solid #e4e4e4;
    &:first-child {
      border-top: 0;
    }
    span {
      float: right;
    }
  }
  .gaibian {
    border-right: 1px solid #fff;
    color: orange;
  }
}
.xz {
  position: absolute;
  z-index: 2;
  background-color: #fff;
  padding: 10px 20px;
  top: -1px;
  left: 261px;
  width: 350px;
  border: 1px solid #ddd;
  li {
    cursor: pointer;
    display: flex;
    align-items: center;
    height: 36px;
    line-height: 36px;
    font-size: 14px;
    color: #888;
    border-bottom: 1px solid #fff;
    .numb {
      font-size: 24px;
      color: orange;
    }
    .ct {
      margin: 0 10px;
      color: orange;
      font-weight: 400;
    }
    &:hover {
      border-bottom: 1px solid #ccc;
    }
  }
}
</style>